namespace Backoffice.Domain.Entities.App
{
    /// <summary>
    /// 文章内容领域实体
    /// </summary>
    public class AppArticle : EntityBase
    {
        public string Title       { get; private set; }   // 标题
        public string Content     { get; private set; }   // 富文本内容
        public string Category    { get; private set; }   // 分类
        public string Tags        { get; private set; }   // 逗号分隔的标签
        public ArticleStatus Status { get; private set; } // 状态：草稿 / 发布 / 下线

        // 导航属性（可选，例如评论、作者等）
        public virtual List<AppArticleTag> ArticleTags { get; private set; } = new();

#pragma warning disable CS8618 // EF 无参构造
        private AppArticle() { }
#pragma warning restore CS8618

        /// <summary>
        /// 创建文章
        /// </summary>
        public AppArticle(string title, string content, string category, string tags, ArticleStatus status = ArticleStatus.Draft)
        {
            Title    = title;
            Content  = content;
            Category = category;
            Tags     = tags;
            Status   = status;
        }

        /// <summary>
        /// 更新文章基本信息
        /// </summary>
        public void UpdateInfo(string title, string content, string category, string tags)
        {
            Title    = title;
            Content  = content;
            Category = category;
            Tags     = tags;
        }

        /// <summary>
        /// 切换文章状态
        /// </summary>
        public void ChangeStatus(ArticleStatus newStatus) => Status = newStatus;

        /// <summary>
        /// 深拷贝克隆（用于树形或列表返回）
        /// </summary>
        public AppArticle Clone()
        {
            return new AppArticle(Title, Content, Category, Tags, Status)
            {
                Id = Id
            };
        }
    }

    /// <summary>
    /// 文章状态枚举
    /// </summary>
    public enum ArticleStatus
    {
        Draft    = 0,
        Published = 1,
        Offline   = 2
    }
}